package com.example.xiongmao.controller;


import com.example.xiongmao.entity.DTO.CommonStatus;
import com.example.xiongmao.entity.DTO.user.UserChargeDTO;
import com.example.xiongmao.entity.DTO.user.addUserChargeDTO;
import com.example.xiongmao.entity.PageResult;
import com.example.xiongmao.entity.Result;
import com.example.xiongmao.entity.VO.user.userChargeVO;
import com.example.xiongmao.service.UserChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userCharge")
public class userChargeController {

    @Autowired
    private UserChargeService userChargeService;
    // 分页条件查询
    @GetMapping
    public Result<PageResult> list(UserChargeDTO userChargeDTO){
        PageResult pageResult = userChargeService.list(userChargeDTO);
        System.out.println("page:"+userChargeDTO.getPage()+"pageSize"+userChargeDTO.getPageSize());
        return Result.success(pageResult);
    }

    // 新增用户
    @PostMapping
    public Result addUser(@RequestBody addUserChargeDTO addUser){
        userChargeService.add(addUser);
        return Result.success();
    }

    // 编辑回显
    @GetMapping("/{id}")
    public Result getByUserId(@PathVariable Integer id){
        userChargeVO users = userChargeService.getbyId(id);
        return Result.success(users);
    }

    // 编辑用户信息
    @PutMapping
    public Result updateUser(@RequestBody addUserChargeDTO updateUser){
        System.out.println("前端传回来的："+updateUser);
        userChargeService.updateUser(updateUser);
        return Result.success();
    }

    // （批量）删除用户信息
    @DeleteMapping
    public Result deleteUser(@RequestParam List<Integer> ids){
        System.out.println("当前要删除的ids:"+ids);
        userChargeService.deleteBatch(ids);
        return Result.success();
    }

    // 禁用用户状态
    @PutMapping("/status")
    public Result UserStatusChange(@RequestBody CommonStatus userStatus){
        System.out.println("当前要修改状态的ids:"+userStatus);
        userChargeService.userStatusChange(userStatus);
        return Result.success();
    }
}
